package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllTaskAttachments", query = "select myTaskAttachment from TaskAttachment myTaskAttachment"),
		@NamedQuery(name = "findTaskAttachmentByCreatedDate", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.createdDate = ?1"),
		@NamedQuery(name = "findTaskAttachmentByDescription", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.description = ?1"),
		@NamedQuery(name = "findTaskAttachmentByDescriptionContaining", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.description like ?1"),
		@NamedQuery(name = "findTaskAttachmentByFileName", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.fileName = ?1"),
		@NamedQuery(name = "findTaskAttachmentByFileNameContaining", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.fileName like ?1"),
		@NamedQuery(name = "findTaskAttachmentByFileSize", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.fileSize = ?1"),
		@NamedQuery(name = "findTaskAttachmentById", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.id = ?1"),
		@NamedQuery(name = "findTaskAttachmentByPrimaryKey", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.id = ?1"),
		@NamedQuery(name = "findTaskAttachmentByRowkey", query = "select myTaskAttachment from TaskAttachment myTaskAttachment where myTaskAttachment.rowkey = ?1") })
@Table(catalog = "sow", name = "task_attachment")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "TaskAttachment")
public class TaskAttachment implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "FILE_NAME", length = 100, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String fileName;
	/**
	 */

	@Column(name = "FILE_SIZE", precision = 12, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Long fileSize;
	/**
	 */
	
	@Column(name = "FILE_TYPE", length = 50)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String fileType;
   /**
    */

	@Column(name = "ROWKEY", length = 40, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String rowkey;
	/**
	 */

	@Column(name = "DESCRIPTION", length = 100)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar createdDate;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User user;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TASK_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Task task;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	/**
	 */
	public String getFileName() {
		return this.fileName;
	}

	/**
	 */
	public void setFileSize(Long fileSize) {
		this.fileSize = fileSize;
	}

	/**
	 */
	public Long getFileSize() {
		return this.fileSize;
	}
	
	/**
    */

   public String getFileType() {
      return fileType;
   }

   /**
    */

   public void setFileType(String fileType) {
      this.fileType = fileType;
   }

	/**
	 */
	public void setRowkey(String rowkey) {
		this.rowkey = rowkey;
	}

	/**
	 */
	public String getRowkey() {
		return this.rowkey;
	}

	/**
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 */
	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 */
	public Calendar getCreatedDate() {
		return this.createdDate;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 */
	@JsonIgnore
	public Task getTask() {
		return task;
	}

	/**
	 */
	public TaskAttachment() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(TaskAttachment that) {
		setId(that.getId());
		setFileName(that.getFileName());
		setFileSize(that.getFileSize());
		setFileType(that.getFileType());
		setRowkey(that.getRowkey());
		setDescription(that.getDescription());
		setCreatedDate(that.getCreatedDate());
		setUser(that.getUser());
		setTask(that.getTask());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("fileName=[").append(fileName).append("] ");
		buffer.append("fileSize=[").append(fileSize).append("] ");
		buffer.append("fileType=[").append(fileType).append("] ");
		buffer.append("rowkey=[").append(rowkey).append("] ");
		buffer.append("description=[").append(description).append("] ");
		buffer.append("createdDate=[").append(createdDate).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof TaskAttachment))
			return false;
		TaskAttachment equalCheck = (TaskAttachment) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
